/*
 * @Author: Marte
 * @Date:   2016-10-24 11:25:43
 * @Last Modified by:   Marte
 * @Last Modified time: 2016-10-25 10:44:25
 */

'use strict';

var _ = require('underscore');

module.exports = function(sequelize, DataTypes) {
    var RemarkGroup = sequelize.define('RemarkGroup', {
        groupName: {
            type: DataTypes.STRING,
            allowNull: false,
            comment: '评语分组',
            validate: {
                notEmpty: {
                    msg: '不允许为空'
                }
            }
        }

    }, {
        charset: 'utf8',
        classMethods: {
            associate: function(models) {
                RemarkGroup.belongsTo(models.Remark, {
                    constraints: false
                });

            },
            fetch: function(op) {
                return this
                    .findAll(_.extend({
                        order: [
                            'createdAt'
                        ],
                        raw: true
                    }, op || {}));
            },
            fetchByRemark: function(remarkId, op) {
                return this.find(_.extend({
                    where: {
                        RemarkId: remarkId
                    },
                    raw: true
                }, op || {}));
            }
        }
    });
    return RemarkGroup;
};
